<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习2</title>
    <style>
         .image{
            width:350px;
            height:350px;
            background: url(../images/11.bmp);
            border:1px solid #ccc;
            position: relative;
        }
        .point-div{
            width:175px;
            height:175px;
            background: rgba(0,0,255,0.5);
            position: absolute;
            left:0px;
            top:0px;
        }
        .point-lg-div{
            width:400px;
            height:400px;
            background: url(../images/1.bmp) no-repeat;
            border: 1px solid #ccc;
            position: absolute;
            left:400px;
            top:0;
        }
    </style>
</head>
<body>
    <div class="image">
    </div>
    <script>
        let image = document.querySelector(".image");
        image.onmouseenter = function(){
            image.innerHTML = `<div class="point-div"></div>
                        <div class="point-lg-div"></div>`;
            let pointDiv = document.querySelector(".point-div");
            let pointLgDiv = document.querySelector(".point-lg-div");
            image.onmousemove= function(e){
                pointDiv.style.left = e.x - this.offsetLeft - 87.5 + "px";
                pointDiv.style.top = e.y - this.offsetTop - 87.5 + "px";
                let left = parseInt(pointDiv.style.left);
                let top = parseInt(pointDiv.style.top);
                if(left >= 175){
                    pointDiv.style.left = "175px";
                }
                if(left <= 0){
                    pointDiv.style.left = "0";
                }
                if(top >= 175){
                    pointDiv.style.top = "175px";
                }
                if(top <= 0){
                    pointDiv.style.top = "0";
                }
                let lgX = parseInt(pointDiv.style.left)/350*800;
                let lgY = parseInt(pointDiv.style.top)/350*800;
                pointLgDiv.style.backgroundPosition = `-${lgX}px -${lgY}px`;

            }            
        }
        image.onmouseleave = function(){
            image.innerHTML = "";
        }
    </script>
</body>
</html>